﻿<UserControl x:Class="PasswordSafe.UserControls.PasswordGrid" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x:Name="passwordGrid"
        xmlns:odc="clr-namespace:Odyssey.Controls;assembly=Odyssey" xmlns:local="clr-namespace:PasswordSafe.Controls"
        xmlns:uc="clr-namespace:PasswordSafe.UserControls" xmlns:biz="clr-namespace:PasswordSafe.Data.Biz;assembly=PasswordSafe.Data"
        xmlns:classes="clr-namespace:PasswordSafe.Classes" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <UserControl.InputBindings>
        <KeyBinding Command="uc:PasswordGrid.FocusSearchBoxCommand" Key="F3" />
        <KeyBinding Command="uc:PasswordGrid.FocusSearchBoxCommand" Modifiers="Control" Key="F" />
    </UserControl.InputBindings>
    <UserControl.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/DataTemplates.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate DataType="{x:Type biz:Password}">
                <odc:DropDownButton Content="{Binding Name,UpdateSourceTrigger=PropertyChanged}" PopupPlacement="Bottom" Margin="4,0,0,0" x:Name="btn"
                        odc:RibbonBar.AffectsDropDown="False" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
                    <odc:DropDownButton.DropDownButtonContent>
                        <Grid Width="24" HorizontalAlignment="Stretch">
                            <Image Source="/img/faves16.png" VerticalAlignment="Center" Width="16" Height="16" Stretch="Fill" HorizontalAlignment="Center"
                                    Margin="1" Visibility="{Binding IsFavorite, Converter={StaticResource visibilityConverter},Mode=OneWay}" />
                            <Image Source="/img/nofaves16.png" VerticalAlignment="Center" Width="16" Height="16" Stretch="Fill" HorizontalAlignment="Center"
                                    Margin="1"
                                    Visibility="{Binding IsFavorite, Converter={StaticResource visibilityConverter},Mode=OneWay, ConverterParameter=-}" />
                        </Grid>
                    </odc:DropDownButton.DropDownButtonContent>
                    <odc:DropDownButton.DropDownHeader>
                        <odc:ClickableTreeView ItemTemplate="{StaticResource FavoriteFolderTemplate}" Padding="4" Focusable="False" FontWeight="Normal"
                                odc:RibbonOption.CloseDropDownOnClick="False" KeyboardNavigation.ControlTabNavigation="None"
                                KeyboardNavigation.DirectionalNavigation="Cycle" BorderThickness="0" MaxHeight="240" ItemsSource="{Binding PasswordFolders}">
                            <odc:ClickableTreeView.ItemContainerStyle>
                                <Style TargetType="{x:Type odc:ClickableTreeViewItem}">
                                    <Setter Property="IsExpanded" Value="true" />
                                    <Setter Property="Command" Value="{x:Static local:Commands.ToggleFaveCommand}" />
                                </Style>
                            </odc:ClickableTreeView.ItemContainerStyle>
                        </odc:ClickableTreeView>
                    </odc:DropDownButton.DropDownHeader>
                </odc:DropDownButton>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsModified}" Value="True">
                        <Setter Property="Control.FontWeight" Value="Bold" TargetName="btn" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ResourceDictionary>

    </UserControl.Resources>
    <Grid Grid.Column="1" Grid.Row="1" Focusable="False">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Grid.ColumnSpan="2" Margin="0,2,2,0" Focusable="False">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" MinWidth="100" />
                <ColumnDefinition Width="200" MinWidth="140" MaxWidth="250" />
            </Grid.ColumnDefinitions>
            <odc:BreadcrumbBar x:Name="breadcrumb" Grid.Column="0" HorizontalAlignment="Stretch" Margin="0,0,4,0" odc:KeyTip.Key="B"
                    DataContext="{Binding SelectedNode, ElementName=passwordGrid}" BreadcrumbItemTemplate="{StaticResource BreadcrumbCategoryTemplate}"
                    Root="{Binding BreadcrumbRoot, ElementName=passwordGrid}" SelectedBreadcrumbChanged="OnCategoryBreadcrumbItemSelected"
                    PathBinding="{Binding Path, Mode=OneWay}" TraceBinding="{Binding Name}" ImageBinding="{Binding Converter={StaticResource imageConverter}}"
                    HideRootNode="True" BreadcrumbItemTemplateSelector="{StaticResource breadcrumbSelector}"
                    DropDownItemsSource="{Binding BreadcrumbHierarchy, ElementName=passwordGrid}">
            </odc:BreadcrumbBar>
            <GridSplitter Grid.Column="0" Width="5" ShowsPreview="False" Margin="0" Background="Transparent" BorderThickness="0" />

            <odc:OdcTextBox x:Name="searchBox" Grid.Column="1" Margin="0" Info="Search..." odc:KeyTip.Key="L" odc:KeyTip.XOffset="-20" odc:KeyTip.YOffset="2"
                    Text="{Binding SearchText, ElementName=passwordGrid,UpdateSourceTrigger=PropertyChanged}">
                <odc:OdcTextBox.Buttons>
                    <odc:ImageButton Image="/img/del16.png" x:Name="delBtn" Visibility="Collapsed" Click="OnSearchBoxDelBtnClick" />
                    <odc:ImageButton Image="/img/Search16.png" IsEnabled="False" x:Name="fndBtn" />
                </odc:OdcTextBox.Buttons>
            </odc:OdcTextBox>
        </Grid>

        <Grid Focusable="False" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="150" MaxWidth="340" Width="240" x:Name="PasswordColumn" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <ListView x:Name="PasswordsListView" Grid.Column="0" Grid.Row="1" Margin="0,4,4,4" Padding="4" HorizontalAlignment="Stretch" odc:KeyTip.Key="PA"
                    odc:KeyTip.YOffset="4" odc:KeyTip.XOffset="4" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                    odc:RibbonOption.CloseDropDownOnClick="False" VerticalAlignment="Stretch"
                    ItemsSource="{Binding Passwords,ElementName=passwordGrid,UpdateSourceTrigger=PropertyChanged}"
                    SelectedItem="{Binding SelectedPassword,Mode=TwoWay, ElementName=passwordGrid}"
                    BorderBrush="{DynamicResource {ComponentResourceKey odc:Skins, BorderBrush}}">
            </ListView>
            <GridSplitter Grid.Column="0" Grid.Row="1" Width="5" ShowsPreview="False" Background="Transparent" Margin="0" />

            <Border Grid.Column="1" Grid.Row="1" Margin="0,4,2,4" Focusable="False" DataContext="{Binding SelectedItem,ElementName=PasswordsListView}"
                    Background="#60FFFFFF" BorderBrush="{DynamicResource {ComponentResourceKey odc:Skins, BorderBrush}}" BorderThickness="1">
                <Grid Visibility="{Binding Converter={StaticResource nullToVisibleConverter}}" Focusable="False">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid Margin="0,0,0,2" Focusable="False">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Text="Name" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="14"
                                FontWeight="Bold" Margin="4,2,4,2" />
                        <odc:OdcTextBox Grid.Column="1" Text="{Binding Name,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch"
                                x:Name="PasswordName" VerticalAlignment="Center" Margin="4,8,4,4" FontWeight="Bold" odc:KeyTip.Key="N" />

                        <TextBlock Text="Category" Grid.Row="1" Grid.Column="0" Margin="4,2,4,2" HorizontalAlignment="Right" VerticalAlignment="Center" />

                        <odc:BreadcrumbBar Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" Margin="4,0,4,0" x:Name="FieldBreadcrumb"
                                odc:KeyTip.Key="CC" BreadcrumbItemTemplate="{StaticResource BreadcrumbCategoryTemplate}"
                                Root="{Binding RootCategory, ElementName=passwordGrid}"
                                Path="{Binding CategoryPath,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TraceBinding="{Binding Name}"
                                ImageBinding="{Binding Converter={StaticResource imageConverter}}" HideRootNode="True"
                                BreadcrumbItemTemplateSelector="{StaticResource breadcrumbSelector}"
                                DropDownItemsSource="{Binding CategoryHierarchy, ElementName=passwordGrid}">
                        </odc:BreadcrumbBar>

                    </Grid>
                    <ScrollViewer CanContentScroll="True" HorizontalScrollBarVisibility="Disabled" Grid.Row="1" Focusable="False"
                            VerticalScrollBarVisibility="Auto" HorizontalContentAlignment="Stretch" odc:RibbonOption.AnimateTransition="True">
                        <ItemsControl x:Name="FieldListControl" Margin=" 0" Background=" Transparent" Focusable="False" ItemsSource="{Binding Fields}"
                                HorizontalContentAlignment="Stretch" ItemTemplateSelector="{StaticResource PasswordItemSelector}" VerticalAlignment="Stretch"
                                HorizontalAlignment="Stretch">
                            <ItemsControl.ItemContainerStyle>
                                <Style TargetType="FrameworkElement">
                                    <Setter Property="Focusable" Value="False" />
                                </Style>
                            </ItemsControl.ItemContainerStyle>
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Margin="0,10,0,10" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                    </ScrollViewer>
                </Grid>
            </Border>
        </Grid>
    </Grid>

</UserControl>
